{{- /* Desktop header */ -}}
<header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="{{ .Site.Home.RelPermalink }}" title="{{ .Site.Title }}">
                {{- with .Site.Params.header.title -}}
                    {{- with .logo -}}
                        {{- dict "Src" . "Class" "logo" | partial "plugin/img.html" -}}
                    {{- end -}}
                    {{- with .pre -}}
                        <span class="header-title-pre">{{ . | safeHTML }}</span>
                    {{- end -}}
                    {{- if .typeit -}}
                        {{- $id := dict "Content" .name "Scratch" $.Scratch | partial "function/id.html" -}}
                        <span id="{{ $id }}" class="typeit"></span>
                        {{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}}
                    {{- else -}}
                        {{- .name -}}
                    {{- end -}}
                    {{- with .post -}}
                        <span class="header-title-post">{{ . | safeHTML }}</span>
                    {{- end -}}
                {{- else -}}
                    {{- .Site.Title -}}
                {{- end -}}
            </a>
        </div>
        <div class="menu">
            <div class="menu-inner">
                {{- range .Site.Menus.main -}}
                    {{- $url := .URL | relLangURL -}}
                    {{- with .Page -}}
                        {{- $url = .RelPermalink -}}
                    {{- end -}}
                    <a class="menu-item{{ if $.IsMenuCurrent `main` . | or ($.HasMenuCurrent `main` .) | or (eq $.RelPermalink $url) }} active{{ end }}" href="{{ $url }}"{{ with .Title }} title="{{ . }}"{{ end }}{{ if (urls.Parse $url).Host }} rel="noopener noreffer" target="_blank"{{ end }}>
                        {{- .Pre | safeHTML }} {{ .Name }} {{ .Post | safeHTML -}}
                    </a>
                {{- end -}}
                {{- if .Site.Menus.main -}}
                    <span class="menu-item delimiter"></span>
                {{- end -}}

                {{- if .Site.Params.search.enable -}}
                    <span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="{{ .Site.Params.search.placeholder | default (T `searchPlaceholder`) }}" id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="{{ T `search` }}">
                            <i class="fas fa-search fa-fw" aria-hidden="true"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="{{ T `clear` }}">
                            <i class="fas fa-times-circle fa-fw" aria-hidden="true"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin" aria-hidden="true"></i>
                        </span>
                    </span>
                {{- end -}}
                <a href="javascript:void(0);" class="menu-item theme-switch" title="{{ T "switchTheme" }}">
                    <i class="fas fa-adjust fa-fw" aria-hidden="true"></i>
                </a>
                {{- if .Site.IsMultiLingual -}}
                <a href="javascript:void(0);" class="menu-item language" title="{{ T "selectLanguage" }}">
                    <i class="fa fa-globe" aria-hidden="true"></i>                      
                    <select class="language-select" id="language-select-desktop" onchange="location = this.value;">
                        {{- if eq .Kind "404" -}}
                            {{- /* https://github.com/dillonzq/LoveIt/issues/378 */ -}}
                            {{- range .Sites -}}
                                {{- $link := printf "%v/404.html" .LanguagePrefix -}}
                                <option value="{{ $link }}"{{ if eq . $.Site }} selected{{ end }}>
                                    {{- .Language.LanguageName -}}
                                </option>
                            {{- end -}}
                        {{- else -}}
                            {{- range .AllTranslations -}}
                                <option value="{{ .RelPermalink }}"{{ if eq .Lang $.Lang }} selected{{ end }}>
                                    {{- .Language.LanguageName -}}
                                </option>
                            {{- end -}}
                        {{- end -}}
                    </select>
                </a>
            {{- end -}}
            </div>
        </div>
    </div>
</header>

{{- /* Mobile header */ -}}
<header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="{{ .Site.Home.RelPermalink }}" title="{{ .Site.Title }}">
                    {{- with .Site.Params.header.title -}}
                        {{- with .logo -}}
                            {{- dict "Src" . "Class" "logo" | partial "plugin/img.html" -}}
                        {{- end -}}
                        {{- with .pre -}}
                            <span class="header-title-pre">{{ . | safeHTML }}</span>
                        {{- end -}}
                        {{- if .typeit -}}
                            {{- $id := dict "Content" .name "Scratch" $.Scratch | partial "function/id.html" -}}
                            <span id="{{ $id }}" class="typeit"></span>
                            {{- dict $id (slice $id) | dict "typeitMap" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}}
                        {{- else -}}
                            {{- .name -}}
                        {{- end -}}
                        {{- with .post -}}
                            <span class="header-title-post">{{ . | safeHTML }}</span>
                        {{- end -}}
                    {{- else -}}
                        {{- .Site.Title -}}
                    {{- end -}}
                </a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile">
            {{- if .Site.Params.search.enable -}}
                <div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="{{ .Site.Params.search.placeholder | default (T `searchPlaceholder`) }}" id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="{{ T `search` }}">
                            <i class="fas fa-search fa-fw" aria-hidden="true"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="{{ T `clear` }}">
                            <i class="fas fa-times-circle fa-fw" aria-hidden="true"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin" aria-hidden="true"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        {{ T `cancel` }}
                    </a>
                </div>
            {{- end -}}
            {{- $currentPage := . -}}
            {{- range .Site.Menus.main -}}
                {{- $url := .URL | relLangURL -}}
                {{- with .Page -}}
                    {{- $url = .RelPermalink -}}
                {{- end -}}
                <a class="menu-item" href="{{ $url }}" title="{{ .Title }}"{{ if (urls.Parse $url).Host }} rel="noopener noreffer" target="_blank"{{ end }}>
                    {{- .Pre | safeHTML }}{{ .Name }}{{ .Post | safeHTML -}}
                </a>
            {{- end -}}
            <a href="javascript:void(0);" class="menu-item theme-switch" title="{{ T "switchTheme" }}">
                <i class="fas fa-adjust fa-fw" aria-hidden="true"></i>
            </a>
            {{- if .Site.IsMultiLingual -}}
            
                <a href="javascript:void(0);" class="menu-item" title="{{ T "selectLanguage" }}">
                    <i class="fa fa-globe fa-fw" aria-hidden="true"></i>
                    <select class="language-select" onchange="location = this.value;">
                        {{- if eq .Kind "404" -}}
                            {{- /* https://github.com/dillonzq/LoveIt/issues/378 */ -}}
                            {{- range .Sites -}}
                                {{- $link := printf "%v/404.html" .LanguagePrefix -}}
                                <option value="{{ $link }}"{{ if eq . $.Site }} selected{{ end }}>
                                    {{- .Language.LanguageName -}}
                                </option>
                            {{- end -}}
                        {{- else -}}
                            {{- range .AllTranslations -}}
                                <option value="{{ .RelPermalink }}"{{ if eq .Lang $.Lang }} selected{{ end }}>
                                    {{- .Language.LanguageName -}}
                                </option>
                            {{- end -}}
                        {{- end -}}
                    </select>
                </a>
            {{- end -}}
        </div>
    </div>
</header>

{{- if .Site.Params.search.enable -}}
    <div class="search-dropdown desktop">
        <div id="search-dropdown-desktop"></div>
    </div>
    <div class="search-dropdown mobile">
        <div id="search-dropdown-mobile"></div>
    </div>
{{- end -}}
